import onlineListener from './online'
import chatListener from './chat'
import drawListener from './draw'
import { IO_CONNECT, SPACE_CHAT, SPACE_DRAW, SPACE_ONLINE } from '../const'

const runSocket = (io, socketData) => {
  const { online, draw, chat } = socketData

  const chatIO = io.of(SPACE_CHAT)
  const drawIO = io.of(SPACE_DRAW)
  const onlineIO = io.of(SPACE_ONLINE)

  chatIO.on(IO_CONNECT, socket => {
    chatListener(chatIO, socket, chat)
  })

  drawIO.on(IO_CONNECT, socket => {
    drawListener(drawIO, socket, draw)
  })

  onlineIO.on(IO_CONNECT, socket => {
    onlineListener(onlineIO, socket, online)
  })
}

export default runSocket
